from flask import jsonify, request
from datetime import datetime
from decimal import Decimal
from commons.controller.base_controller import BaseController
from approval_service.approval.service.travel_approval_service import TravelApprovalService
from commons.controller.base_controller import BaseController


class TravelApprovalController(BaseController):
    def __init__(self):
        self.travel_approval_service = TravelApprovalService()

    def get_travel_approval_by_id(self):
        """
        根据审批出差申请ID获取审批出差申请信息。
        """
        # 从请求体解析参数
        data = request.get_json()
        travel_approval_id = data.get("travelApprovalId")

        return BaseController.get_success_response(self,
                                                   self.travel_approval_service.
                                                   get_travel_approval_by_travel_approval_id(
                                                       travel_approval_id))

    def get_travel_approval_by_travel_id(self):
        """
        根据出差申请ID获取审批出差申请信息。
        """
        # 从请求体解析参数
        data = request.get_json()
        travel_id = data.get("travelId")

        return BaseController.get_success_response(self,
                                                   self.travel_approval_service.get_travel_approval_by_travel_id(travel_id))

    def get_approve_travel_record(self):
        """
        获取审批的出差申请记录。
        """
        # 从请求体解析参数
        data = request.get_json()
        user_id = data.get("userId")
        page_no = data.get("pageNo")
        page_size = data.get("pageSize")

        return BaseController.get_success_response(self, self.travel_approval_service.get_approve_travel_record(
            user_id, page_no, page_size))
